<script lang="ts" setup>
import { PeaceColumn } from '@/components/type/PeaceColumn'
import { ComponentEnum } from '@/enum/ComponentEnum'
import { NFlex } from 'naive-ui'
import { ifFilterUndefinedRepeatNum } from '@/infrastructure/PeaceDataTable/util/PeaceColumnUtil.ts'
import { ObjectUtil } from '@/util/ObjectUtil'
import { PeaceForm } from '@/components/type/PeaceForm'

const props = withDefaults(
  defineProps<{
    peaceForm: PeaceForm
    index: {
      type: Number,
      required: true
    }
    formModel: {
      type: Record<string, unknown>,
      required: true
    }
  }>(),
  {
    show: false,
  },
)
const formParamObj = computed({
  get:()=> props.formModel,
})
const ifMatcherComponent = computed(()=>{
  return props.peaceForm.componentEnum
    && props.peaceForm.componentEnum === ComponentEnum.RADIO
    && ObjectUtil.isNullOrUndefined(props.peaceForm.peaceRender)
})
</script>
<template>
  <template v-if="ifMatcherComponent && ObjectUtil.isNullOrUndefined(props.peaceForm.repeatRender)">
    <n-form-item :label="peaceForm?.title as string" :path="peaceForm?.key">
      <n-radio-group
        v-model:value="formParamObj[peaceForm?.key] as string | number | boolean"
        :name="index + '_radiogroup'"
      >
        <n-flex>
          <n-radio
            v-for="(peace, radioIndex) in peaceForm.optionConfig?.peaceOption"
            :key="index + radioIndex"
            :value="getRadioValue(peace, peaceForm.optionConfig?.peaceValueField)"
          >
            {{ getRadioLabel(peace, peaceForm.optionConfig?.peaceLabelField) }}
          </n-radio>
        </n-flex>
      </n-radio-group>
    </n-form-item>
  </template>
  <template v-if="ifMatcherComponent && ObjectUtil.isNotNullAndUndefined(props.peaceForm.repeatRender)">
    <n-form-item :label="peaceForm?.title as string">
      <template v-for="(numVal,numIndex) in props.peaceForm?.repeatRender?.num" :key="index + '_' + numIndex">
        <n-flex>
          <n-radio-group
            v-model:value="formParamObj[peaceForm?.repeatRender?.returnFileNames[numIndex]] as string | number | boolean"
            :name="index + '_radiogroup'"
          >
            <n-flex>
              <n-radio
                v-for="(peace, radioIndex) in peaceForm.optionConfig?.peaceOption"
                :key="index + radioIndex"
                :value="getRadioValue(peace, peaceForm.optionConfig?.peaceValueField)"
              >
                {{ getRadioLabel(peace, peaceForm.optionConfig?.peaceLabelField) }}
              </n-radio>
            </n-flex>
          </n-radio-group>
        </n-flex>
      </template>
    </n-form-item>
  </template>
</template>
<style scoped></style>
